<template>
  <div>
    <h3>文件上传测试</h3>
    <input type="file" ref="myFile"/>
    <el-button type="success" @click="importData" size="mini">确定上传</el-button>


    <h3>上传的图片文件</h3>
    <div>
      <img :src="imgSrc" width="100px" height="100px"/>
    </div>


  </div>
</template>

<script>
  export default {
    name: 'UploadFileTest',
    data() {
      return {
        imgSrc: ""
      }
    },
    methods: {
      importData() {
        // alert("哈哈哈哈, 开始上传文件");
        debugger
        let myFile = this.$refs.myFile;
        let files = myFile.files;
        let file = files[0];
        let formData = new FormData();
        formData.append("file", file);
        this.uploadFileRequest("/upload", formData).then(res => {
          console.log(res);
          this.imgSrc = res.data;
        });
      }
    }
  }
</script>

<style scoped>

</style>
